#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 12 15:22:09 2018

@author: jia.liu
"""
import pandas as pd

# 输入训练好的pca模型和对应的df
# 返回进行pca时各列系数 
# 转化的计算方法（有专门的函数）：(原始数据矩阵 - pca.mean_ ) × pca.components_.T
def my_pca_coefficient(df, pca):
    df_res = pd.DataFrame()
    df_res['col_name'] = df.columns
    for i in range(pca.n_components):
        df_res['coef_%d'%(i+1)] = pca.components_[i]
    df_res['col_mean'] = pca.mean_
    return df_res
    